import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;

/**
 * ChooseFile_Window
 * JFrame with a JFileChooser, for changing the image in Template_Window.
 */
public class ChooseFile_Window extends JFrame {
	
	private JPanel jContentPane = null;
	
	public ChooseFile_Window(Window_Controller wc) {
		super();
		initialize(wc);
	}
	
	/**
	 * Initialize the JFrame
	 * @param wc
	 */
	private void initialize(Window_Controller wc) {
		this.setContentPane(getJContentPane(wc));
		this.setTitle("Find dit billede?");
		this.setSize(540,390);
		this.setResizable(false);
		this.setVisible(false);
	}
	
	/**
	 * Initialize the JPanel
	 * @param wc				(windowcontroller) Window_Controller
	 * @return
	 */
	private JPanel getJContentPane(Window_Controller wc) {
		
		final Window_Controller wcon = wc;
		final JFileChooser chooser = new JFileChooser();
		
		chooser.addActionListener(new ActionListener(){
			  public void actionPerformed(ActionEvent e){
				  if (e.getActionCommand() == "CancelSelection") {
					  setVisible(false);
				  }
				  else if (e.getActionCommand() == "ApproveSelection") {
					  wcon.change_Template_Window_img(chooser.getSelectedFile().toString());
					  setVisible(false);
				  }
			  }
		});
		
		jContentPane = new JPanel();
		jContentPane.add(chooser);
		return jContentPane;
	}
}
